package cn.tedu.mall.seckill;

import cn.tedu.mall.common.config.MallCommonConfiguration;
import cn.tedu.mall.seckill.init.SeckillInitializer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;

@SpringBootApplication
@Import(MallCommonConfiguration.class)
@MapperScan("cn.tedu.mall.seckill.mapper")
public class SeckillApplication {
    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(SeckillApplication.class);
        springApplication.addListeners(
                new ApplicationListener<ApplicationReadyEvent>() {
                    @Override
                    public void onApplicationEvent(ApplicationReadyEvent applicationEvent) {
                        ConfigurableApplicationContext applicationContext = applicationEvent.getApplicationContext();
                        SeckillInitializer seckillInitializer = applicationContext.getBean(SeckillInitializer.class);
                        seckillInitializer.initStart();

                    }
                }
        );
        springApplication.run(args);
    }
}
